import pandas as pd
import numpy as np

# Series (一维数组结构)
# 从列表创建

s1 = pd.Series([1,3,5,7,9])

print("Series from list")
print(s1)

# 带自定义索引的Series
s2 = pd.Series([1,3,5,7,9], index=['a','b','c','d','e'])
print("\nSeries with custom index:")
print(s2)

# 从字典创建
s3 = pd.Series({
    '苹果': 5,
    '香蕉': 3 ,
    '橙子': 8
})
print("\nSeries from dict:")
print(s3)

# DataFrame (二维数组结构)
# 从字典创建
df1 = pd.DataFrame({
    '姓名': ['张三', '李四', '王五'],
    '年龄': [25, 30, 35],
    '城市': ['北京', '上海', '广州']
})
print("DataFrame from dict:")
print(df1)

#从二维数组创建
df2 = pd.DataFrame(
    np.random.randn(3,4),
    columns=['A', 'B', 'C', 'D'],
    index=['row1', 'row2', 'row3']
)
print("\nDataFrame from 2D array:")
print(df2)

# DataFrame 的基本属性
print("\nDataFrame 的基本属性:")
print("形状:",df1.shape)
print("列名:",df1.columns.tolist())
print("索引:",df1.index.tolist())
print("数据类型:",df1.dtypes)

